package manager.entitycreator;

import java.sql.ResultSet;
import java.sql.SQLException;

import util.DateUtil;
import entity.Round;

/**
 * Implements methods that describe how to extract round information from the
 * given ResultSet.
 * 
 * @author sheryl.tay.2012, mohameds.2012, huangjm.2012, huiwensong.2012, jaslin.wee.2012
 * 
 */
public class RoundCreator implements EntityCreator<Round> {

	@Override
	public Round newEntityFromResultSet(ResultSet rs) throws SQLException {
		return newRoundFromResultSet(rs);
	}

	/**
	 * Creates a new Round entity from the given result set.
	 * 
	 * @param rs
	 *            result set containing round information
	 * @return a new Round entity with information extracted from the result set
	 * @throws SQLException
	 */
	static Round newRoundFromResultSet(ResultSet rs) throws SQLException {
		return new Round(rs.getInt("round_roundNo"), rs.getBoolean("isOpen"),
				DateUtil.combineDateAndTime(rs.getDate("round_startDatetime"),
						rs.getTime("round_startDatetime")),
				DateUtil.combineDateAndTime(rs.getDate("round_endDatetime"),
						rs.getTime("round_endDatetime")));
	}

}
